package com.novasoftware.novagooglemap.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.LockSupport;

import com.novasoftware.novagooglemap.R;
import com.novasoftware.novagooglemap.R.drawable;
import com.novasoftware.novagooglemap.R.id;
import com.novasoftware.novagooglemap.R.layout;
import com.novasoftware.novagooglemap.adapter.MainAdapter;
import com.novasoftware.novagooglemap.db.DatabaseImpl;
import com.novasoftware.novagooglemap.db.entity.NovaCategory;
import com.novasoftware.novagooglemap.framework.activity.BaseActivity;
import com.novasoftware.novagooglemap.framework.util.SystemUiHider;

import android.R.bool;
import android.renderscript.RenderScriptGL.SurfaceConfig;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class MainActivity extends BaseActivity {

	private ListView listView;
	
	@Override
	protected boolean IsHiderUI() {
		return true;
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode==KeyEvent.KEYCODE_HOME)
		{
			moveTaskToBack(true);
			return true;
		}
	    if (keyCode == KeyEvent.KEYCODE_BACK) {
	        moveTaskToBack(true);
	        return true;
	    }
	    return super.onKeyDown(keyCode, event);
	}
	
	@Override
	protected void InitializeService()
	{
		new DatabaseImpl(MainActivity.this);
	}

	@Override
	protected int getContent() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
        new Thread() {
            public void run() {
                try { 
                    sleep(10000);
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    finish();
                }
            }
        }.start();
		return R.layout.main;
	}

	@Override
	protected void LocalizeControls() {
		listView = (ListView)findViewById(R.id.list);
	
		ArrayList<NovaCategory> list = new ArrayList<NovaCategory>();
		NovaCategory novaCategory1 = new NovaCategory();
		novaCategory1.Id=0;
		novaCategory1.CaseStudy=20;
		novaCategory1.Name="Nova Developer";
		novaCategory1.ImageId= R.drawable.ic_launcher;
		
		NovaCategory novaCategory2 = new NovaCategory();
		novaCategory2.Id=1;
		novaCategory2.CaseStudy=21;
		novaCategory2.ImageId = R.drawable.android;
		novaCategory2.Name="Android developer";

		list.add(novaCategory1);
		list.add(novaCategory2);
		list.add(novaCategory1);
		list.add(novaCategory2);
		list.add(novaCategory1);
		list.add(novaCategory2);
		list.add(novaCategory1);
		list.add(novaCategory2);
		list.add(novaCategory1);
		list.add(novaCategory2);
		list.add(novaCategory1);
		list.add(novaCategory2);
		
		MainAdapter adapter = new MainAdapter(MainActivity.this,list);
		listView.setAdapter(adapter);
	}

	@Override
	protected void RegisterEvents() { 
		listView.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				SetControlsView();
			}
		});
	}
	
	@Override
	protected View GetControlsView() {
		return findViewById(R.id.fullscreen_content_controls);
	}

	@Override
	protected View GetUIView() {
		return findViewById(R.id.list);
	}

	@Override
	protected View GetDelayHideView() {
		return findViewById(R.id.dummy_button);
	}

}
